Completed
Push — master ( b8d297...c6cce1 )
by Maxence
02:13
created

elements.fillMembersSearch   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
rs 9.4285
1
/*
2
 * Circles - Bring cloud-users closer together.
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Maxence Lange <[email protected]>
8
 * @copyright 2017
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
/** global: OC */
27
/** global: OCA */
28
/** global: Notyf */
29
30
/** global: nav */
31
/** global: actions */
32
/** global: curr */
33
/** global: api */
34
35
36
var elements = {
37
38
	newTypeDefinition: null,
39
	newType: null,
40
	newSubmit: null,
41
	newName: null,
42
	navigation: null,
43
	circlesList: null,
44
	circlesSearch: null,
45
	emptyContent: null,
46
	mainUI: null,
47
	mainUIMembers: null,
48
	membersSearchResult: null,
49
50
	joinCircleAccept: null,
51
	joinCircleReject: null,
52
	joinCircleRequest: null,
53
	joinCircleInvite: null,
54
	joinCircle: null,
55
	leaveCircle: null,
56
	addMember: null,
57
58
59
	initElements: function () {
60
61
		elements.newTypeDefinition = $('#circles_new_type_definition');
62
		elements.newType = $('#circles_new_type');
63
		elements.newSubmit = $('#circles_new_submit');
64
		elements.newName = $('#circles_new_name');
65
		elements.navigation = $('#app-navigation.circles');
66
		elements.circlesList = $('#circles_list');
67
		elements.circlesSearch = $('#circles_search');
68
		elements.circlesFilters = $('#circles_filters');
69
		elements.circlesDetails = $('#circle_details');
70
		elements.emptyContent = $('#emptycontent');
71
		elements.mainUI = $('#mainui');
72
		elements.mainUIMembers = $('#memberslist_table');
73
		elements.membersSearchResult = $('#members_search_result');
74
		elements.memberDetails = $('#memberdetails');
75
		elements.memberRequest = $('#member_request');
76
77
		elements.joinCircleInteraction = $('#sjoincircle_interact');
78
		elements.joinCircleAccept = $('#joincircle_acceptinvit');
79
		elements.joinCircleReject = $('#joincircle_rejectinvit');
80
		elements.joinCircleRequest = $('#joincircle_request');
81
		elements.joinCircleInvite = $('#joincircle_invit');
82
		elements.joinCircle = $('#joincircle');
83
		elements.leaveCircle = $('#leavecircle');
84
		elements.rightPanel = $('#rightpanel');
85
		elements.addMember = $('#addmember');
86
		elements.remMember = $('#remmember');
87
	},
88
89
90
	initTweaks: function () {
91
		$.fn.emptyTable = function () {
92
			this.children('tr').each(function () {
93
				if ($(this).attr('class') !== 'header') {
94
					$(this).remove();
95
				}
96
			});
97
		};
98
	},
99
100
101
	initUI: function () {
102
		elements.newTypeDefinition.children('div').fadeOut(0);
103
		$('#circles_new_type_' + elements.newType.children('option:selected').val()).fadeIn(
104
			0);
105
106
		elements.newType.hide();
107
		elements.newSubmit.hide();
108
		elements.newTypeDefinition.hide();
109
110
		$('.icon-circles').css('background-image',
111
			'url(' + OC.imagePath('circles', 'colored') + ')');
112
113
		var theme = $('#body-user').find('#header').css('background-color');
114
		elements.circlesList.css('background-color', theme);
115
		elements.circlesDetails.css('background-color', theme);
116
		elements.rightPanel.css('background-color', theme);
117
118
		elements.membersSearchResult.hide();
119
	},
120
121
122
	/**
123
	 *
124
	 */
125
	initExperienceCirclesList: function () {
126
127
		elements.circlesList.children('div').on('click', function () {
128
			nav.displayCirclesList($(this).attr('circle-type'));
129
		});
130
131
		this.initExperienceCirclesListFromSearch();
132
		this.initExperienceCirclesListFromFilter();
133
	},
134
135
136
	initExperienceCirclesListFromSearch: function () {
137
138
		this.circlesSearch.on('input property paste focus', function () {
139
			var search = $(this).val().trim();
140
			if (curr.searchCircle === search) {
141
				return;
142
			}
143
144
			curr.searchCircle = search;
145
			api.searchCircles(curr.circlesType, curr.searchCircle, curr.searchFilter,
146
				actions.listCirclesResult);
147
		});
148
	},
149
150
151
	initExperienceCirclesListFromFilter: function () {
152
153
		this.circlesFilters.on('input property paste focus', function () {
154
			var searchFilter = $(this).val();
155
			if (curr.searchFilter === searchFilter) {
156
				return;
157
			}
158
159
			curr.searchFilter = searchFilter;
160
			api.searchCircles(curr.circlesType, curr.searchCircle, curr.searchFilter,
161
				actions.listCirclesResult);
162
		});
163
164
	},
165
166
167
	initExperienceMemberDetails: function () {
168
		elements.memberRequest.hide();
169
		elements.remMember.on('click', function () {
170
			api.removeMember(curr.circle, curr.member, actions.removeMemberResult);
171
		});
172
173
		$('#joincircle_acceptrequest').on('click', function () {
174
			api.addMember(curr.circle, curr.member, actions.addMemberResult);
175
		});
176
		$('#joincircle_rejectrequest').on('click', function () {
177
			api.removeMember(curr.circle, curr.member, actions.removeMemberResult);
178
		});
179
180
	},
181
182
183
	/**
184
	 *
185
	 */
186
	initAnimationNewCircle: function () {
187
188
		elements.newName.on('keyup', function () {
189
			actions.onEventNewCircleName();
190
		});
191
192
		elements.newType.on('change', function () {
193
			actions.onEventNewCircleType();
194
		});
195
196
		elements.newSubmit.on('click', function () {
197
			api.createCircle(elements.newType.val(), elements.newName.val(),
198
				actions.createCircleResult);
199
		});
200
201
	},
202
203
204
	fillMembersSearch: function (exact, partial) {
205
		this.fillExactMembersSearch(exact);
206
		this.fillPartialMembersSearch(partial);
207
		elements.membersSearchResult.children().first().css('border-top-width', '0px');
208
	},
209
210
	fillExactMembersSearch: function (exact) {
211
212
		$.each(exact, function (index, value) {
213
			elements.membersSearchResult.append(
214
				'<div class="members_search exact" searchresult="' +
215
				value.value.shareWith + '">' + value.label + '   (' +
216
				value.value.shareWith + ')</div>');
217
		});
218
219
	},
220
221
	fillPartialMembersSearch: function (partial) {
222
		$.each(partial, function (index, value) {
223
			var currSearch = elements.addMember.val().trim();
224
			var line = value.label + '   (' + value.value.shareWith + ')';
225
			if (currSearch.length > 0) {
226
				line = line.replace(new RegExp('(' + currSearch + ')', 'gi'), '<b>$1</b>');
227
			}
228
229
			elements.membersSearchResult.append(
230
				'<div class="members_search" searchresult="' + value.value.shareWith + '">' + line +
231
				'</div>');
232
		});
233
234
	},
235
236
237
	resetCirclesList: function () {
238
239
		elements.navigation.addClass('selected');
240
		elements.navigation.children().each(function () {
241
			if ($(this).attr('id') !== 'circles_search' &&
242
				$(this).attr('id') !== 'circles_filters') {
243
				$(this).remove();
244
			}
245
		});
246
	},
247
248
249
	removeMemberslistEntry: function (membername) {
250
		this.mainUIMembers.children("[member-id='" + membername + "']").each(
251
			function () {
252
				$(this).hide(300);
253
			});
254
	},
255
256
257
	generateTmplCircle: function (entry) {
258
		var tmpl = $('#tmpl_circle').html();
259
260
		tmpl = tmpl.replace(/%title%/g, entry.name);
261
		tmpl = tmpl.replace(/%type%/g, entry.type);
262
		tmpl = tmpl.replace(/%owner%/g, entry.owner.user_id);
263
		tmpl = tmpl.replace(/%status%/g, entry.user.status);
264
		tmpl = tmpl.replace(/%level_string%/g, entry.user.level_string);
265
		tmpl = tmpl.replace(/%count%/g, entry.count);
266
		tmpl = tmpl.replace(/%creation%/g, entry.creation);
267
268
		return tmpl;
269
	},
270
271
272
	generateTmplMember: function (entry) {
273
		var tmpl = $('#tmpl_member').html();
274
275
		tmpl = tmpl.replace(/%username%/g, entry.user_id);
276
		tmpl = tmpl.replace(/%level%/g, entry.level);
277
		tmpl = tmpl.replace(/%levelstring%/g, entry.level_string);
278
		tmpl = tmpl.replace(/%status%/g, entry.status);
279
		tmpl = tmpl.replace(/%joined%/g, entry.joined);
280
		tmpl = tmpl.replace(/%note%/g, entry.note);
281
282
		return tmpl;
283
	}
284
285
286
};